package com.hq.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hq.service.impl.CommentImpl;
import com.hq.utils.JSONObjectUtil;

/**
 * Servlet implementation class CommentObtainServlet
 */
@WebServlet("/CommentObtainServlet")
public class CommentObtainServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String conver_id = request.getParameter("conver_id");
		String skip = request.getParameter("skip");
		PrintWriter print = response.getWriter();
		if(conver_id == null) {
			print.print(JSONObjectUtil.createLoginPushMoreErrorComment());
		}else if(skip == null){
			print.print(JSONObjectUtil
					.createLoginPushMoreComment(new CommentImpl().getMoreComment(Integer.valueOf(conver_id), null)));
		}else {
			print.print(JSONObjectUtil
					.createLoginPushMoreComment(new CommentImpl().getMoreComment(Integer.valueOf(conver_id), Integer.valueOf(skip))));
		}
		
		print.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
